package myapp.view 
{
	import com.bumpslide.events.UIEvent;
	import com.bumpslide.ui.Lightbox;

	/**
	 * @author David Knape
	 */
	public class PopupHolder extends AppComponent 
	{

		public var popup:ImagePopup;
		
		override protected function addChildren():void
		{
			super.addChildren();
			popup = new ImagePopup();
			addChild(popup);
			
			// init bindings
			model.bind('selectedImage', this, popupSelectedImage); 
			
			// listen for UI events...
			addEventListener(Lightbox.EVENT_CLOSED, handlePopupClose);
		}
		
		private function popupSelectedImage():void 
		{
			if(model.selectedImage) {
				popup.url = model.selectedImage.imageURL; 
			} else {
				popup.url = null;
			} 
		}
		
		/**
		 * Update state when popup is closed
		 */
		private function handlePopupClose(event:UIEvent):void 
		{
			model.selectedImage = null;
		}
	}
}
